import { createRouter, createWebHistory } from "vue-router"
import pinia from '../store'
import { useRouterStore, useIndexStore } from "../store/path"
const routerStore = useRouterStore(pinia)
const indexStore = useIndexStore(pinia)

const routes = [
    {
        path: "/",
        name: "home",
        component: () => import('@/view/index/index.vue'),
        redirect: 'luckyStick',
        children: [{
            path: 'luckyStick',
            name: 'luckyStick',
            component: () => import('@/view/draw_lots/index.vue'),
            children: [{
                path: 'setpage',
                name: 'setpage',
                component: () => import('@/view/draw_lots/setpage/index.vue'),
            }, {
                path: 'setname',
                name: 'setname',
                component: () => import('@/view/draw_lots/setname/index.vue'),
            }]
        },
        {
            path: 'luckyBall',
            name: 'luckyBall',
            component: () => import('@/view/lucky_ball/index.vue'),
        },
        {
            path: 'grandSpin',
            name: 'grandSpin',
            component: () => import('@/view/grand_spin/index.vue'),
        }]
    },
    {
        path: '/:pathMatch(.*)',
        redirect: '/404'
    }
]


const router = createRouter({
    history: createWebHistory(),
    linkActiveClass: 'active',
    routes: routes,
    scrollBehavior() {
        return { top: 0 }
    },
})
router.beforeEach((to, from, next) => {
    routerStore.$patch({
        currentPage: to.name
    })
    // indexStore.$patch({
    //     showLoading: true
    // })
    next()
})
export default router